package com.cyl.config.ecxle;

import java.lang.reflect.Field;
import java.util.Map;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.framework.config.LocalDataUtil;

public class ExcelSysDictIntegerConvert implements Converter<Integer>{
	    
	@Override
    public WriteCellData<?> convertToExcelData(Integer valueInt, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
		if(valueInt==null) {
            return new WriteCellData<>("");
        }
		try {
			Map<String, Map<String,String>> sysDictMap = (Map<String, Map<String,String>>) LocalDataUtil.getVar(Constants.SYS_DICT_TYPE);
			String value = valueInt.toString();
			Field field = contentProperty.getField();
	        String sys_dict_type = sysDictMap.get("SYS_FIELD_NAME_DATA1233212").get(field.getName());
	        if(sysDictMap!=null && sysDictMap.containsKey(sys_dict_type)) {
	        	Map<String,String> sysDictValue = sysDictMap.get(sys_dict_type);
	        	if(sysDictValue.containsKey(value)) {
	                return new WriteCellData<>(sysDictValue.get(value));
	        	}
	        }
		} catch (Exception e) {
			// TODO: handle exception
		}
        
        return new WriteCellData<>("");
		
    }
   
	@Override
    public Class<Integer> supportJavaTypeKey() {
        return Integer.class;
    }
 
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.NUMBER;
    }

}